import { PayloadAction, createSlice } from "@reduxjs/toolkit";

interface dataConfigFase{
    token:string,
    userData:object,
    staticUrl:string
}

// 初始化数据
const initialState={
    token:"", //用户token
    userData:{}, //登录信息,
    staticUrl:'' //图片静态地址
}
export const getDataConfig=createSlice({
    name:"getDataConfig",
    initialState,
    reducers:{
        setToken:(state:dataConfigFase,token:PayloadAction<string>)=>{
             state.token = token.payload;
        },
        setUserData:(state:dataConfigFase,userData:PayloadAction<object>)=>{
            state.userData = userData.payload;
       },
       setStaticUrl:(state:dataConfigFase,staticUrl:PayloadAction<string>)=>{
           state.staticUrl = staticUrl.payload;
       },
    //    清空数据
       clearUserData:(state:dataConfigFase)=>{
        state.userData={}
        state.token=""
       }
    }
})

 
// 导出
export const { setToken,setUserData,clearUserData ,setStaticUrl} = getDataConfig.actions
export default getDataConfig.reducer